{include file="styles/header.tpl"}
<link href="{$smarty.const.HOST_STATIC}/libs/js/calendar/calendar-mos.css" rel="stylesheet">
<script src="{$smarty.const.HOST_STATIC}/libs/js/calendar/calendar_mini.js"></script>
<script src="{$smarty.const.HOST_STATIC}/libs/js/calendar/init_cal.js"></script>
<script src="{$smarty.const.HOST_STATIC}/libs/js/calendar/lang/calendar-en.js"></script>
<div id="content" class="box">
	<h1>Prepare PO</h1>
	<fieldset>
		<legend>Search</legend>
		<div style="float:left">
		<form method="get" action="">
			<!--<label>SKU : </label><input type="text" size="40" name="sku" value="{$strSku}" />
			<label>&nbsp;&nbsp; -->
			Choose Supplier :</label>
			<select name="supplier">
				<option value="" {if $strSupplier==""} selected="selected"{/if}> &nbsp;&nbsp;======== All ======== &nbsp;&nbsp; </option>
				{foreach from=$arrSupplier item=supplier}
					<option value="{$supplier.id}"{if $strSupplier==$supplier.id} selected="selected"{/if}>&nbsp;&nbsp;{$supplier.name} [{$supplier.id}] &nbsp;&nbsp;</option>
				{/foreach}
			</select>
			<label>Total Sku :</label>
				<select name="total_sku">
				    <option value="" {if $strTotalSku==''} selected="selected"{/if}>&nbsp;&nbsp;All&nbsp;&nbsp;</option>	
					<option value="11" {if $strTotalSku=='11'} selected="selected"{/if}>&nbsp;&nbsp;> 0 &nbsp;&nbsp; </option>
					<option value="1"{if $strTotalSku=='1'} selected="selected"{/if}>&nbsp;&nbsp;> 1 &nbsp;&nbsp; </option>
					<option value="2"{if $strTotalSku=='2'} selected="selected"{/if}>&nbsp;&nbsp;> 2 &nbsp;&nbsp; </option>
					<option value="3"{if $strTotalSku=='3'} selected="selected"{/if}>&nbsp;&nbsp;> 3 &nbsp;&nbsp; </option>
					<option value="4"{if $strTotalSku=='4'} selected="selected"{/if}>&nbsp;&nbsp;> 4 &nbsp;&nbsp; </option>
					<option value="5"{if $strTotalSku=='5'} selected="selected"{/if}>&nbsp;&nbsp;> 5 &nbsp;&nbsp; </option>
					<option value="6"{if $strTotalSku=='6'} selected="selected"{/if}>&nbsp;&nbsp;> 6 &nbsp;&nbsp; </option>
					<option value="7"{if $strTotalSku=='7'} selected="selected"{/if}>&nbsp;&nbsp;> 7 &nbsp;&nbsp; </option>
					<option value="8"{if $strTotalSku=='8'} selected="selected"{/if}>&nbsp;&nbsp;> 8 &nbsp;&nbsp; </option>
					<option value="9"{if $strTotalSku=='9'} selected="selected"{/if}>&nbsp;&nbsp;> 9 &nbsp;&nbsp; </option>
					<option value="10"{if $strTotalSku=='10'} selected="selected"{/if}>&nbsp;&nbsp;>10 &nbsp;&nbsp; </option>
				</select>
			<input type="submit" value="Filter" class="bt" />
			<input type="submit" value="Refresh" class="bt" />
		</form>
		</div>
		<div style="float:right">
		<h2>
			({$intTotal} record{if $intTotal>2}s{/if})
			{if $intTotal>0}
			|
			<a href="{$smarty.const.HOST_ADMIN}/supplier/export?sku={$strSku}&supplier={$strSupplier}">Export</a>
			{/if}
		</h2>
		</div>
	</fieldset>
	
	<table width="100%" id="fx">
	<tr>
	{foreach from=$arrTitle item=title}
		{if ($title !='id' && $title !='supplier_id')}
		<th>
			{if $title =='name'}
				Supplier name
			{else}
				{$title|dragon_column_name}
			{/if}
		</th>
		{/if}
	{/foreach}
	<th>
	Action
	</th>
	</tr>
	{assign var='c' value=0}
	{foreach from=$arrResult item=result}
		<tr {if ($c % 2 == 1) } class="bg" {/if}>
			{assign var='c' value=$c+1}
		{foreach from=$result item=cell key=f name=i}
		{if ($f !='id' &&  $f !='supplier_id')}
			<td>
				{if ($f=='po_number') }
			    {if ($result.total_sku > 0)}
					<a href="javascript:void(0)" onclick="PODetail.pop_up({$result.supplier_id})">
							{$cell}
							</a>
				{else}
					{$cell}
				{/if}
				{elseif ($f=='name') }
					<a href="javascript:void(0)" onclick="POSupplier.pop_up({$result.supplier_id})">
							{$cell} [{$result.supplier_id}]
					</a>
				{elseif ($f=='logistic_type') }
						<select id="{$f}__{$result.id}">
							<option value="" {if $cell==""} selected="selected"{/if}> </option>
								{foreach from=$arrLogisticType item=type}
								<option value="{$type}" {if $cell==$type} selected="selected"{/if}> {$type} </option>
								{/foreach}
						</select>
				{elseif ($f=='logistic_method') }
							<select id="{$f}__{$result.id}">
								<option value="" {if $cell==""} selected="selected"{/if}> </option>
								{foreach from=$arrLogisticMethod item=method}
								<option value="{$method}" {if $cell==$method} selected="selected"{/if}> {$method} </option>
								{/foreach}
							</select>
				{elseif ($f=='logistic_date') }
					  <input id="{$f}__{$result.id}" onclick="return showCalendar('{$f}__{$result.id}', 'y-mm-dd');"
									{if ($cell)}
										value="{$cell}" 
									{else}
									   value=""
									{/if}
									size="9"/>
				{elseif ($f=='logistic_eta') }
					<select id="{$f}__{$result.id}">
								<option value="" {if $cell==""} selected="selected"{/if}> </option>
								{foreach from=$arrLogisticEta item=eta}
								<option value="{$eta}" {if $cell==$eta} selected="selected"{/if}> {$eta} </option>
								{/foreach}
					</select>
				{else}
					{$cell}
				{/if}		
			</td>
		{/if}
		{/foreach}
		<td><a href="javascript:void(0)" id="save_{$result.id}" class="save-ajax"> Save </a></td>
	</tr>
	{/foreach}
	</table>
	
	{include file="styles/paginator.tpl"}
</div>
<div id="currenttab" class="category_prepare_po" style="display: none;">
{literal}
  <script type="text/javascript">
	$(".save-ajax").click(function(){
		 var id = this.id;
		 var idSplit = id.split("_");
		 var saveId = idSplit[1];

		 var logisticType	= $("#logistic_type__" + saveId).val();
		 var logisticMethod = $("#logistic_method__" + saveId).val();
		 var logisticDate	= $("#logistic_date__" + saveId).val();
		 var logisticEta	= $("#logistic_eta__" + saveId).val();

    	 $.ajax({
			   url: HOST + "/supplier/save-header",
			   data:{id : saveId, 
					 logistic_type : logisticType,
					 logistic_method : logisticMethod,
					 logistic_date : logisticDate, 
					 logistic_eta : logisticEta	
			   },
			   success:function(data) {
					alert("Save success!");
			   }
		 });
	});

  </script>
{/literal}
{include file="styles/footer.tpl"}